import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @description： Routing之订阅模式 Topic
 * Topic类型的Exchange和Direct相比，都是可以根据RoutingKey把消息路由到不同队列，只不过Topic类型Exchange可以让
 * 队列在绑定Routing Key的时候使用统配符，这种模式Routing Key一般都是由一个或者多个单词组成，多个单词之间以“.”分割
 * @Author MRyan
 * @Date 2020/11/9 20:58
 * @Version 1.0
 */
public class Providers {

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接对象
        Connection connection = RabbitMqUtil.getConnection("192.168.43.78", 5672, "/ems", "ems", "123");
        //获取通道对象
        Channel channel = connection.createChannel();
        //声明交换机以及交换机类型topic
        channel.exchangeDeclare("topics", "topic");
        //发送消息
        String routekey = "user.delete.save";
        channel.basicPublish("topics", routekey, null, ("topic动态路由模型{" + routekey + "}").getBytes());
        //关闭资源
        RabbitMqUtil.close(connection, channel);

    }
}
